package message

import (
	"common-api/serialization"
)

type Message interface {
	Decode([]byte) error
	Encode() (error, []byte)
	GetMsgCode() int
	GetMsgType() int
}

type HeaderMessage struct {
	Type int    `json:"type"`
	Code int    `json:"code"`
	Body []byte `json:"-"`
}

func (l *HeaderMessage) GetMsgCode() int {
	return l.Code
}
func (l *HeaderMessage) GetMsgType() int {
	return l.Type
}

func (l *HeaderMessage) Decode(data []byte) error {
	err := serialization.JsonDecode(data, l)
	if err != nil {
		return err
	}
	return nil
}

func (l *HeaderMessage) Encode() (error, []byte) {
	// Assume JSON encoding for demonstration purposes
	return serialization.JsonEncode(l)
}

const (
	CommonResponseCode      = 0
	RegisterRequestCode     = 1
	LoginRequestCode        = 2
	LoginResponseCode       = 3
	HeartRequestBeatCode    = 4
	PrivateChatRequestCode  = 5
	PrivateChatResponseCode = 6
)

const RequestType = 1
const ResponseType = 2
const SuccessCode = 0
const ErrorCode = -1
